
var POSTYPE = cc.Enum({
    center: 0,
    down: 1,
});

const {ccclass, property} = cc._decorator;

@ccclass
export default class ToastView extends cc.Component {

    @property(cc.Node)
    nodePanel: cc.Node = null;

    @property(cc.Label)
    labelAlert: cc.Label = null;

    init (params) {
        this.labelAlert.string = params.message;
     
        if (params.posType == POSTYPE.down) {
            this.nodePanel.y = -200;
        }
        this.node.runAction(cc.sequence(cc.moveBy(0.5,cc.v2(0,60)),cc.fadeOut(0.5),cc.callFunc(()=>{
            this.node.active = false;
        })));
    }

    showToast(params: any) {
        if (!this.node.active) {
            this.node.active = true;
            this.node.y =  this.node.y-60;
            this.node.opacity = 255;

            this.labelAlert.string = params.message;
         
            if (params.posType == POSTYPE.down) {
                this.nodePanel.y = -200;
            }
            this.node.runAction(cc.sequence(cc.moveBy(0.8,cc.v2(0,60)),cc.delayTime(0.5),cc.fadeOut(0.5),cc.callFunc(()=>{
                this.node.active = false;
            })));
        } else {
            this.labelAlert.string = params.message;
        }
    }
}
